package com.briup.jd2511.web02.controller;

import com.briup.jd2511.web02.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class ResponseController {

    @RequestMapping("/toPage")
    public String toPage(){
        // 这里的字符串不是我们一开始学习的数据了
        // 而是项目中页面的文件名字
        return "a.html";
    }

    @RequestMapping("/getJsonBean")
    @ResponseBody
    public Student getJsonBean(){
        Student student = new Student();
        student.setName("张三");
        student.setAge(20);
        return student;
    }

    @RequestMapping("/getJsonList")
    @ResponseBody
    public List<Student> getJsonList(){
        Student s1 = new Student();
        s1.setName("tom");
        s1.setAge(20);
        Student s2 = new Student();
        s2.setName("jerry");
        s2.setAge(22);
        Student s3 = new Student();
        s3.setName("bob");
        s3.setAge(21);
        List<Student> list = new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        return list;
    }
}
